package com.yfp.operation.controller;

import cn.hutool.core.util.BooleanUtil;
import com.yfp.common.core.domain.R;
import com.yfp.common.core.web.controller.BaseController;
import com.yfp.common.core.web.page.TableDataInfo;
import com.yfp.operation.domain.dto.*;
import com.yfp.operation.domain.vo.*;
import com.yfp.operation.service.ActivitySignInsService;
import com.yfp.operation.domain.dto.*;
import com.yfp.operation.domain.vo.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/activity-sign-ins")
@Tag(name = "pc-打卡管理")
public class ActivitySignInsController extends BaseController {

    @Resource
    private ActivitySignInsService activitySignInService;

    @Operation(summary = "新增打卡活动-校验")
    @PostMapping("/create/check")
    public R<Integer> createCheck(@RequestBody ActivitySignInsCreateReqDTO activitySignIns) {
        Boolean check = activitySignInService.createCheck(activitySignIns);
        Integer canBuyInteger = BooleanUtil.toInteger(check);
        return R.ok(canBuyInteger);
    }

    @Operation(summary = "新增打卡活动")
    @PostMapping("/create")
    public R<Void> create(@RequestBody ActivitySignInsCreateReqDTO activitySignIns) {
        activitySignInService.create(activitySignIns);
        return R.ok();
    }

    @Operation(summary = "查询打卡活动列表")
    @GetMapping("/list")
    public R<TableDataInfo<ActivitySignInsSearchReqVO>> searchList(ActivitySignInsSearchReqDTO searchReqDTO) {
        TableDataInfo<ActivitySignInsSearchReqVO> activitySignInsList = activitySignInService.searchList(searchReqDTO);
        return R.ok(activitySignInsList);
    }

    @Operation(summary = "查询打卡奖励列表")
    @GetMapping("/reward/list")
    public R<TableDataInfo<ActivitySignInsSearchRewardReqVO>> searchRewardList(ActivitySignInsSearchRewardReqDTO searchReqDTO) {
        TableDataInfo<ActivitySignInsSearchRewardReqVO> activitySignInsList = activitySignInService.searchRewardList(searchReqDTO);
        return R.ok(activitySignInsList);
    }

    @Operation(summary = "查询参与人数列表")
    @GetMapping("/participation/list")
    public R<TableDataInfo<ActivitySignInsSearchParticipationReqVO>> searchParticipationList(ActivitySignInsSearchParticipationReqDTO searchReqDTO) {
        TableDataInfo<ActivitySignInsSearchParticipationReqVO> activitySignInsList = activitySignInService.searchParticipationList(searchReqDTO);
        return R.ok(activitySignInsList);
    }

    @Operation(summary = "查询参与人数列表-获得奖励列表")
    @GetMapping("/participation-award/list")
    public R<TableDataInfo<ActivitySignInsSearchParticipationAwardReqVO>> searchParticipationAwardList(ActivitySignInsSearchParticipationAwardReqDTO searchReqDTO) {
        TableDataInfo<ActivitySignInsSearchParticipationAwardReqVO> activitySignInsList = activitySignInService.searchParticipationAwardList(searchReqDTO);
        return R.ok(activitySignInsList);
    }

    @Operation(summary = "查询打卡活动详情")
    @GetMapping("/{id}")
    public R<ActivitySignInsVO> getInfo(@PathVariable Long id) {
        ActivitySignInsVO info = activitySignInService.getInfo(id);
        return R.ok(info);
    }

    @Operation(summary = "失效打卡活动")
    @DeleteMapping("/failure/{id}")
    public R<Void> failure(@PathVariable Long id) {
        activitySignInService.failure(id);
        return R.ok();
    }

    @Operation(summary = "删除打卡活动")
    @DeleteMapping("/delete/{id}")
    public R<Void> delete(@PathVariable Long id) {
        activitySignInService.delete(id);
        return R.ok();
    }

    @PostMapping("/incrementCount")
    @Operation(summary = "增加打卡次数")
    public R<Void> incrementCount(@RequestParam("clientId") String clientId, @RequestParam("cityName") String cityName) {
        activitySignInService.incrementCount(clientId, cityName);
        return R.ok();
    }
}
